import sys
import argparse
import flowtool
import http_tls
import sites_plugin

parser = argparse.ArgumentParser("This program includes all kinds of QA testing scripts.")

parser.add_argument("-f"
    , "--flowtool"
    , help="Run flowtool against a single pcap file."
    , metavar="path_pcap_file")

parser.add_argument("-F"
    , "--flowtool_folder"
    , help="Run flowtool against all pcap files in this directory and sub-directories."
    , metavar="path_pcap_folder")

parser.add_argument("-m"
    , "--miss_http_tls"
    , help="Look through this file to find fail classified HTTP & TLS hosts & referers."
    , metavar=("path_flowtool_output", "path_output"))

parser.add_argument("-M"
    , "--missed_http_tls_tcp_folder"
    ,
                    help="Look through folders for '.pkt.log' file and '.flow.log'to find fail classified HTTP & TLS hosts & referers and tcp streams."
    , metavar=("path_flowtool_output", "path_output")
    , nargs=2)

parser.add_argument("--check_guid_format"
    , help="Look through this file to find duplicates and wrong format guid definitions."
    , metavar=("path_guids_file"))

parser.add_argument("--check_rule_format"
    , help="Look through this file to find duplicates and wrong format rules."
    , metavar=("path_rules_file"))

parser.add_argument("--make_sites_pattern"
    , help="Read 2 files, one guid file and one rule file, read each guid and find matching rules to make web pattern."
    , metavar=("path_guids_file", "path_rule_file")
    , nargs=2)

parser.add_argument("--make_refered_sites_pattern"
    , help="Read 2 files, one guid file and one rule file, read each guid and find matching rules to make web pattern."
    , metavar=("path_guids_file", "path_rule_file")
    , nargs=2)

args = parser.parse_args()


def main():
    if args.flowtool:
        ft = flowtool.Flowtool()
        ft.run_flowtool(args.flowtool)

    elif args.flowtool_folder:
        ft = flowtool.Flowtool()
        ft.run_flowtool_folder(args.flowtool_folder)

    elif args.miss_http_tls:
        ht = http_tls.HttpTls()
        ht.missed_http_tls(args.miss_http_tls)

    elif args.missed_http_tls_tcp_folder:
        ht = http_tls.HttpTls()
        ht.missed_http_tls_tcp_folder(args.missed_http_tls_tcp_folder[0], args.missed_http_tls_tcp_folder[1])

    elif args.check_guid_format:
        sites = sites_plugin.SitesPlugin()
        sites.check_guid_format(args.check_guid_format)

    elif args.check_rule_format:
        sites = sites_plugin.SitesPlugin()
        sites.check_rule_format(args.check_rule_format)

    elif args.make_sites_pattern:
        sites = sites_plugin.SitesPlugin()
        sites.make_webpattern_sites(args.make_sites_pattern[0], args.make_sites_pattern[1])

    elif args.make_refered_sites_pattern:
        sites = sites_plugin.SitesPlugin()
        sites.make_webpattern_referer_sites(args.make_refered_sites_pattern[0], args.make_refered_sites_pattern[1])


if __name__ == "__main__":
    sys.exit(main())
